package com.wealth.scsj.p_app.mydefinedview;
import android.app.Dialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.wealth.scsj.p_app.R;

public class  MyPayDialog extends Dialog implements View.OnClickListener{

    private ImageView mCustomIv;
    private TextView mDialogTitleTv;
    private TextView mDialogContentTv;
    private Button mConfirmBtn;
    private Button mCancelBtn;
    private String mTitleText;
    private String mContentText;
    private String mCancelText;
    private String mConfirmText;
    private OnDepositClickListener mCancelClickListener;
    private OnDepositClickListener mConfirmClickListener;
    private boolean mShowCancel;
    private boolean mShowContent;
    private Context mContext;
    private Drawable mCustomImgDrawable;


    public static interface OnDepositClickListener {
        public void onClick (MyPayDialog sweetAlertDialog);
    }

    public MyPayDialog (Context context) {
        super(context);
        this.mContext=context;
        setCancelable(true);
        setCanceledOnTouchOutside(false);
        setContentView(R.layout.dialog_pay_success);
        mCustomIv =findViewById(R.id.custom_image);
        mDialogTitleTv =findViewById(R.id.dialog_title_tv);
        mDialogContentTv =findViewById(R.id.dialog_content_tv);
        mConfirmBtn =findViewById(R.id.confirm_btn);
        mCancelBtn =findViewById(R.id.cancel_btn);

        mConfirmBtn.setOnClickListener(this);
        mCancelBtn.setOnClickListener(this);

        setTitleText(mTitleText);// 默认title是显示状态，
        setContentText(mContentText);//默认是隐藏的 要使用时候 调用此方法 就可以显示
        setCancelText(mCancelText);// 默认是隐藏 要使用时候 调用此方法 就可以显示
        setConfirmText(mConfirmText);
    }

    public MyPayDialog setCustomImage (Drawable drawable) {
        mCustomImgDrawable = drawable;
        if (mCustomIv != null && mCustomImgDrawable != null) {
            mCustomIv.setVisibility(View.VISIBLE);
            mCustomIv.setImageDrawable(mCustomImgDrawable);
        }
        return this;
    }

    public MyPayDialog setCustomImage (int resourceId) {
        return setCustomImage(getContext().getResources().getDrawable(resourceId));
    }


    public String getTitleText () {
        return mTitleText;
    }

    public  MyPayDialog setTitleText(String mTitlet) {
        mTitleText = mTitlet;
        if (mDialogTitleTv != null && mTitleText != null) {
            mDialogTitleTv.setText(mTitleText);
        }
        return this;
    }

    public String getContentText () {
        return mContentText;
    }

    public MyPayDialog setContentText (String text) {
        mContentText = text;
        if (mDialogContentTv != null && mContentText != null) {
            showContentText(true);
            mDialogContentTv.setText(mContentText);
        }
        return this;
    }


    public String getCancelText () {
        return mCancelText;
    }

    public MyPayDialog setCancelText (String text) {
        mCancelText = text;
        if (mCancelBtn != null && mCancelText != null) {
            showCancelButton(true);
            mCancelBtn.setText(mCancelText);
        }
        return this;
    }

    public String getConfirmText () {
        return mConfirmText;
    }

    public MyPayDialog setConfirmText (String text) {
        mConfirmText = text;
        if (mConfirmBtn != null && mConfirmText != null) {
            mConfirmBtn.setText(mConfirmText);
        }
        return this;
    }
    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.cancel_btn) {
            if (mCancelClickListener != null) {
                mCancelClickListener.onClick(MyPayDialog.this);
            } else {
                dismiss();
            }
        } else if (v.getId() == R.id.confirm_btn) {
            if (mConfirmClickListener != null) {
                mConfirmClickListener.onClick(MyPayDialog.this);
            } else {
                dismiss();
            }
        }
    }

    public MyPayDialog setCancelClickListener (OnDepositClickListener listener) {
        mCancelClickListener = listener;
        return this;
    }

    public MyPayDialog setConfirmClickListener (OnDepositClickListener listener) {
        mConfirmClickListener = listener;
        return this;
    }

    public boolean isShowCancelButton () {
        return mShowCancel;
    }

    public MyPayDialog showCancelButton (boolean isShow) {
        mShowCancel = isShow;
        if (mCancelBtn != null) {
            if(mShowCancel){
                mCancelBtn.setVisibility(View.VISIBLE);
                mConfirmBtn.setBackground(mContext.getResources().getDrawable(R.drawable.deposit_pay_btn_submit_bg));
                mConfirmBtn.setTextColor(mContext.getResources().getColor(R.color.main_black_text));
            }else{
                mCancelBtn.setVisibility(View.GONE);
                mConfirmBtn.setBackground(mContext.getResources().getDrawable(R.drawable.deposit_pay_btn_bg));
                mConfirmBtn.setTextColor(mContext.getResources().getColor(R.color.white));
            }
        }
        return this;
    }

    public boolean isShowContentText () {
        return mShowContent;
    }

    public MyPayDialog showContentText (boolean isShow) {
        mShowContent = isShow;
        if (mDialogContentTv != null) {
            mDialogContentTv.setVisibility(mShowContent ? View.VISIBLE : View.GONE);
        }
        return this;
    }
}
